package com.example.campusforumapi.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
//@Data
//@AllArgsConstructor
//@NoArgsConstructor
public class Result implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code;  //因为本次开发采用layui框架进行前端页面搭建，因此code默认  0为返回成功 1为返回状态异常
    private String msg;
    private Object data;

    public Result(){

    }

    public Result(int resultCode,String msg,Object data){
        this.code = resultCode;
        this.msg = msg;
        this.data = data;
    }

    public int getCode(){
        return code;
    }

    public void setCode(int resultCode){
        this.code = resultCode;
    }

    public String getMsg(){
        return msg;
    }

    public void setMsg(String msg){
         this.msg = msg;
    }

    public Object getData(){
        return data;
    }

    public void setData(Object data){
        this.data = data;
    }


    public static Result success (Object data){
        return new Result(0,"success",data);
    }
    public static Result success (){
        return new Result(0,"success",null);
    }
    public static Result error (String msg){
        return new Result(1,msg,null);
    }
    @Override
    public String toString(){
        return "Result{"+
                "resultCode=" + code +
                ", msg='"+msg +'\''+
                ", data=" + data +
                '}';
    }
}
